<?php

namespace App\Http\Requests\Frontend\V10\Users;

use App\Rules\MobileCheck;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UserInfoStoreRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'education'=>['required','string',Rule::in(['01','02','03','04','05','99'])],
            'profession'=>['required','string',Rule::in(['01','02','03','04','05','06','07','08','09','10','11','12'])],
            'company'=>'required',
            'work_address'=>['required',function($attribute, $value, $fail) {
                if(preg_match('/[\x{4e00}-\x{9fa5}]/u', $value)<1){
                    return $fail('地址必须包含中文');
                }
            }],
            'work_phone'=>['required',function($attribute,$value,$fail){
                $reg1 = "/^([0-9]{3,4}-?)?[0-9]{7,8}$/";//固话
                $reg2 = "/^1\d{10}$/";//手机
                if(preg_match($reg1,$value)<1&&preg_match($reg2,$value)<1){
                    return $fail('工作单位电话格式不正确');
                }
            }],
            'linkman_first'=>'required',
            'linkman_first_relation'=>['required','string',Rule::in(['1','2','3','4','5','6','7'])],
            'linkman_first_phone'=>['required',new MobileCheck],
            'linkman_second'=>'required',
            'linkman_second_relation'=>['required','string',Rule::in(['1','2','3','4','5','6','7'])],
            'linkman_second_phone'=>['required',new MobileCheck,'different:linkman_first_phone'],
            'phone_address_list' =>' required',
        ];
    }

    public function messages()
    {
        return [
            'education.required'=>'学历不能为空',
            'education.in'=>'学历不在可用范围',
            'profession.required'=>'职业不能为空',
            'profession.in'=>'职业不在可用范围',
            'company.required'=>'工作单位不能为空',
            'work_address.required'=>'工作地址不能为空',
            'work_phone.required'=>'单位电话不能为空',
            'linkman_first.required'=>'第一个紧急联系人姓名不能为空',
            'linkman_first_phone.required'=>'第一个紧急联系人手机不能为空',
            'linkman_first_relation.required'=>'第一个紧急联系人关系不能为空',
            'linkman_first_relation.in'=>'第一个紧急联系人关系不在可用范围内',
            'linkman_second.required'=>'第二个紧急联系人姓名不能为空',
            'linkman_second_phone.required'=>'第二个紧急联系人手机不能为空',
            'linkman_second_relation.required'=>'第二个紧急联系人关系不能为空',
            'linkman_second_relation.in'=>'第二个紧急联系人关系不在可用范围内',
            'linkman_second_phone.different'=>'两个紧急联系人的号码必须不相同',
            'phone_address_list.required' => '通讯录不能为空'
        ];
    }
}
